package com.viknix.threadpool.manager.config.dump.engine;

import com.viknix.threadpool.manager.config.dump.processor.TpmTaskProcessor;
import com.viknix.threadpool.manager.server.dependence.task.TpmTask;

import java.util.Collection;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @Author: Dongqi
 * @Date: 2021/11/22 10:45
 * @Version 1.0
 * @Description: 抽象 tpm 任务执行引擎。
 */
public abstract class AbstractTpmTaskExecuteEngine<T extends TpmTask> implements TpmTaskExecuteEngine<T> {

    private final ConcurrentHashMap<Object, TpmTaskProcessor> taskProcessors = new ConcurrentHashMap<Object, TpmTaskProcessor>();

    private TpmTaskProcessor defaultTaskProcessor;

    @Override
    public TpmTaskProcessor getProcessor(Object key) {
        return taskProcessors.containsKey(key) ? taskProcessors.get(key) : defaultTaskProcessor;
    }

    @Override
    public Collection<Object> getAllProcessorKey() {
        return taskProcessors.keySet();
    }

    @Override
    public void setDefaultTaskProcessor(TpmTaskProcessor defaultTaskProcessor) {
        this.defaultTaskProcessor = defaultTaskProcessor;
    }
}
